package algotithm.leetcode.listnode.test82;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/18-21:59
 * @URL https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/
 * @Title 82. 删除排序链表中的重复元素 II
 */

import algotithm.leetcode.listnode.ListNode;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if ( head == null || head.next == null ) {
            return head;
        }
        if (head.val == head.next.val ) {
            while (head != null && head.next != null && head.val == head.next.val) {
                head = head.next;
            }
            return deleteDuplicates(head.next);
        } else {
            head.next = deleteDuplicates(head.next);
            return head;
        }

    }
}
